//////////////////////////////////////////////////////////////////////////
//
// GAM203
// Drawable class
// Drawable.h
// 
// Grant Johnson
// Qantm College
// 27/10/2010
//
//////////////////////////////////////////////////////////////////////////

#ifndef DRAWABLE_H
#define DRAWABLE_H

//Forward declarations
struct IDirect3DDevice9;
struct IDirect3DVertexBuffer9;
struct IDirect3DIndexBuffer9;

#include <d3dx9.h>
#include "RenderParams.h"
#include <d3dx9math.h>
#include "AABB.h"

class Drawable
{
public:
	Drawable();
	//Needs to be virtual if there are any virtual functions
	virtual ~Drawable();

	//////////////////////////////////////////////////////////////////////////
	// PURE VIRTUAL
	// For creating the drawable object
	//
	// Paramaters:
	// a_pDevice, the direct3d device
	// a_pTexFileName, a path passed into the function. This can either be used for
	// the texture file name, or for a mesh's file name.
	//
	// Returns false if any step of the creation failed
	// Returns true if created successfully
	//
	//////////////////////////////////////////////////////////////////////////
	virtual bool CreateObject(IDirect3DDevice9* a_pDevice, char* a_pTexFileName) = 0;

	//////////////////////////////////////////////////////////////////////////
	// PURE VIRTUAL
	// For rendering the drawable object
	//
	// Paramaters:
	// a_pDevice, the direct3d device
	//
	// Returns void
	//
	//////////////////////////////////////////////////////////////////////////
	virtual void Render(float a_dt, IDirect3DDevice9* a_pDevice, const RenderParams& a_renderParams) = 0;

	//////////////////////////////////////////////////////////////////////////
	// Set a world matrix to that of the Drawable object
	//
	// Paramaters:
	// a_newWorldMat, a const reference to a matrix with the transformations
	// to be applied to the object
	//
	// Returns void
	//
	//////////////////////////////////////////////////////////////////////////
	void SetWorldMatrix(const D3DXMATRIX& a_newWorldMat);
	
	//////////////////////////////////////////////////////////////////////////
	// Get the world matrix of the drawable object
	//
	// Paramaters:
	// None
	//
	// Returns a const reference to the member data world matrix
	//
	//////////////////////////////////////////////////////////////////////////
	const D3DXMATRIX& GetWorldMatrix() const;

	//////////////////////////////////////////////////////////////////////////
	// Enables or Disable blending for the object
	//
	// Paramaters:
	// a_val, The boolean value stating whether or not to enable blending.
	// By default, blending is disable.
	//
	// Returns void
	//
	//////////////////////////////////////////////////////////////////////////
	void EnableBlending(bool a_val);

	//////////////////////////////////////////////////////////////////////////
	// Sets an object to draw over the stencil buffer.
	// This is set to false by default. When enabled, the object will be drawn
	// over the stencil buffer. 
	//
	// Paramaters:
	// a_val, A boolean value stating whether or not to draw over the stencil
	//
	// Returns void
	//
	//////////////////////////////////////////////////////////////////////////
	void SetDrawOverStencil(bool a_val);

	//////////////////////////////////////////////////////////////////////////
	// Getter function to determine whether or not an object has been set to
	// draw over the stencil buffer
	//
	// Paramaters:
	// None
	//
	// Returns false if the object does not draw over the stencil buffer
	// Return true if the object does draw over the stencil buffer
	//
	//////////////////////////////////////////////////////////////////////////
	bool DoesDrawOverStencil();

	//////////////////////////////////////////////////////////////////////////
	// Get the position of the drawable object
	//
	// Paramaters:
	// None
	//
	// Returns a vector of the position of the drawable
	//
	//////////////////////////////////////////////////////////////////////////
	D3DXVECTOR3 GetPos() { return D3DXVECTOR3(m_worldMatrix._41,m_worldMatrix._42,m_worldMatrix._43); }

	AABB& GetAABB() { return m_aabb; }

	void SetLightable(bool a_val) { m_isLightable = a_val; }
	bool IsLightable() { return m_isLightable; }
	void SetLit(bool a_val) { m_isLit = a_val; }
	bool IsLit() { return m_isLit;}

protected:
	//Store vertex and index data
	IDirect3DVertexBuffer9* m_pVertexBuffer;
	IDirect3DIndexBuffer9* m_pIndexBuffer;

	//World Matrix
	D3DXMATRIX m_worldMatrix;
	//Whether or not to blend object
	bool m_blendEnabled;
	//Whether or not this object is to draw over a stencil
	bool m_drawOverStencil;
	//Whether or not this object can be set on fire - default false
	bool m_isLightable;
	//Whether or not this object is already on fire
	bool m_isLit;

	AABB m_aabb;
};

#endif //DRAWABLE_H